import os
import re

try:
    assert os.getcwd() == os.path.dirname(__file__)
except:
    print("本脚本需要在脚本目录下运行")
    exit()

with open('__profile.ps1', "r") as f:
    content = f.readlines()


for idx, line in enumerate( content):
    p = re.match(r"alias ([a-z0-9]+)=[\"'](.*)[\"']", line, re.I)
    if p:
        alias, cmd = p.groups()
        txt = \
f"""function {alias}(){{
  {cmd} $args
}}\n"""
        content[idx] = txt

with open('user_profile.ps1', 'w') as f:
    f.write("".join(content))